//////////////////////////////////////////////////////////////////////
// BasisObj.h
//
// SHEN Fangyang
// me@shenfy.com
//
// Copyright (C) SHEN Fangyang, 2011, All rights reserved.
//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
//  Brief Description
//
//	Basic interfaces: IRenderable, IResource, IInteractive
//
//////////////////////////////////////////////////////////////////////
#pragma once
#include <BoundingBox.h>

class CDXUTControl;

namespace grflib
{
    namespace engine
    {
        namespace core
        {
            class IRenderable
            {
            public:
                IRenderable(void) {}
                virtual ~IRenderable(void) {};

                virtual HRESULT OnCreateDevice(
                    ID3D10Device *pd3dDevice,
                    const DXGI_SURFACE_DESC *pBufferSurfaceDesc)
                { return S_OK; }

                virtual HRESULT OnResize(
                    ID3D10Device *pd3dDevice, 
                    IDXGISwapChain *pSwapChain,
                    const DXGI_SURFACE_DESC *pBufferSurfaceDesc) 
                { return S_OK; }

                virtual void FrameMove(double fTime, float fElapsedTime) {}

                virtual HRESULT OnRender(
                    ID3D10Device *pd3dDevice,
                    const D3DXMATRIX *pWorldMat,
                    double fTime,
                    float fElapsedTime,
                    UINT pass) 
                {
                    HRESULT hr;
                    V_RETURN(PreRender(pd3dDevice, pWorldMat, fTime, fElapsedTime, pass));
                    V_RETURN(Render(pd3dDevice, pWorldMat, fTime, fElapsedTime, pass));
                    V_RETURN(PostRender(pd3dDevice, pWorldMat, fTime, fElapsedTime, pass));
                    return S_OK;
                }

                virtual void Release(void) {}
                virtual void OnDestroy(void) {}

                virtual BBox<float> &GetBoundingBox(void) = 0;

            protected:
                virtual HRESULT PreRender(ID3D10Device *pd3dDevice,
                    const D3DXMATRIX *pWorldMat,
                    double fTime,
                    float fElapsedTime,
                    UINT pass) { return S_OK; }
                virtual HRESULT PostRender(ID3D10Device *pd3dDevice,
                    const D3DXMATRIX *pWorldMat,
                    double fTime,
                    float fElapsedTime,
                    UINT pass) { return S_OK; }
                virtual HRESULT Render(ID3D10Device *pd3dDevice,
                    const D3DXMATRIX *pWorldMat,
                    double fTime,
                    float fElapsedTime,
                    UINT pass) { return S_OK; }
            };

            class IResource
            {
            public:
                IResource(void) {}
                virtual ~IResource(void) {};

                virtual HRESULT OnCreateDevice(
                    ID3D10Device *pd3dDevice,
                    const DXGI_SURFACE_DESC *pBufferSurfaceDesc) = 0;
                virtual void OnDestroy(void) {}
                virtual void Release(void) {}
            };

            class IInteractive
            {
            public:
                IInteractive(void) {}
                virtual ~IInteractive(void) {};
                virtual HRESULT OnGUIEvent(
                    UINT nEvent, 
                    int nControlID,
                    CDXUTControl *pControl)
                {return S_OK;}

                virtual HRESULT OnKey(UINT nChar, bool bKeyDown, bool bAltDown)
                {return S_OK;}

                virtual HRESULT OnMouse(
                    bool bLeftButtonDown, bool bRightButtonDown, bool bMiddleButtonDown, 
                    bool bSideButton1Down, bool bSideButton2Down, 
                    int nMouseWheelDelta, int xPos, int yPos) 
                { return S_OK; }
            };

            class IPickable
            {
            public:
                IPickable(void) {}
                virtual ~IPickable(void) {}
                virtual HRESULT OnPick(
                    const D3DXVECTOR3 &eyePos, 
                    const D3DXVECTOR3 &viewDir) = 0;
            };

        } //namespace core
    } //namespace engine
} //namespace grflib